home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / filelst2.arc / FILELIST.C next >
Encoding:
C/C++ Source or Header  |  1991-10-07  |  19.9 KB  |  758 lines

  1. /* Filelist.c -- Public Domain -- By Erik Vanriper -- SoWhutWare 1991
  2. **
  3. ** Why?  Because I had nothing better to do.
  4. **
  5. ** I probably could have done this 10 other ways, but I figured this works,
  6. ** so why break it.  The only thing left to add is the wildcard expansion
  7. ** on files.  Maybe tomorrow.....
  8. **
  9. ** I used Turbo C++ 1.0 on this, hack it to your hearts desire.
  10. **
  11. ** If you use a function, please give credit, I know I did.
  12. **
  13. ** If the code format looks wierd, I used a tab stop of 3, and QEdit.
  14. **
  15. */
  16.  
  17. /*------------------------------------------------------------------------------*/
  18.  
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include <string.h>
  22. #include <alloc.h>
  23. #include <dir.h>
  24. #include <sys\types.h>
  25. #include <sys\stat.h>
  26. #include <time.h>
  27. #include <process.h>
  28. #include <dos.h>
  29.  
  30. void bios_open(void);
  31. void bios_scroll_dn(int,int,int,int,int);
  32. void bios_scroll_up(int,int,int,int,int);
  33. void bios_move(int,int);
  34. void vtest(void);
  35. void files(int);
  36. void mainscreen();
  37. void message(char *);
  38. void print_atcolor(int, int, int, unsigned char *);
  39. void areap(char *);
  40. void aread(char *);
  41.  
  42. #define cls() bios_scroll_dn(25,0,0,24,79); bios_move(0,0);
  43. #define NUL '\0'  /* This is part of Bob Stouts "commafmt()" code */
  44. #define B_BLACK      0
  45. #define B_BLUE       16
  46. #define B_GREEN      32
  47. #define B_CYAN       48
  48. #define B_RED        64
  49. #define B_MAGENTA    80
  50. #define B_BROWN      96
  51. #define B_GRAY       112
  52. #define F_BLACK      0
  53. #define F_BLUE       1
  54. #define F_GREEN      2
  55. #define F_CYAN       3
  56. #define F_RED        4
  57. #define F_MAGENTA    5
  58. #define F_BROWN      6
  59. #define F_GRAY       7
  60. #define F_LBLACK     8
  61. #define F_LBLUE      9
  62. #define F_LGREEN     10
  63. #define F_LCYAN      11
  64. #define F_LRED       12
  65. #define F_LMAGENTA   13
  66. #define F_YELLOW     14
  67. #define F_WHITE      15
  68.  
  69. struct xx
  70. {
  71.    char FilePath[70];  /*  69 chars for the path         */
  72.    char AreaDesc[76];  /*  75 chars for the description. */
  73. };
  74.  
  75. struct xx *path[200];  /* Max of 200 areas to malloc() 29,200 bytes. */
  76. struct stat info;
  77. struct tm *tmfile;
  78. struct ffblk fileinfo;
  79. time_t tnow;
  80.  
  81. char drive[MAXDRIVE];
  82. char dir[MAXDIR];
  83. char filename[MAXFILE];
  84. char ext[MAXEXT];
  85. char filepath[MAXPATH];
  86.  
  87. int tempcount = 0;
  88. int start = 0;
  89. int new = 0;
  90. int numfiles[200];
  91. long numbytes, areabytes;
  92.  
  93. char descrip[165], keeppath[70];
  94. char *whitespace = " \t\n\r";
  95. char input[80] = "FILELIST.CFG";  /* Default config file */
  96. char systemname[80];
  97. int days;
  98.  
  99. char cga, ega, vga, mcga, mono, herc, none, color_disp, b_w;
  100. unsigned char cur_attr;
  101. int cur_mode, cur_page;
  102.  
  103. FILE *outfile, *newfile;
  104.  
  105. /*------------------------------------------------------------------------------*/
  106.  
  107. main(int argc, char *argv[])
  108. {
  109.    FILE *fp;
  110.    /*char tempbuff[100];*/
  111.    int t;
  112.    numbytes = areabytes = 0;
  113.  
  114.    time(&tnow);
  115.    bios_open();
  116.  
  117.    for(t=0; t < 200; t++)
  118.    {
  119.       if((path[t] = malloc(sizeof(struct xx))) == NULL)
  120.       {
  121.          puts("not enough memory!  aborting...");
  122.          exit(255);
  123.       }
  124.    }
  125.  
  126.    mainscreen();
  127.  
  128.    if(argc > 1)                 /* assume that argv[1] is a valid config file */
  129.    {
  130.       strcpy(input, argv[1]);
  131.       sprintf(descrip,"Using configuration file %s",input);
  132.       areap(descrip);
  133.    }
  134.  
  135.    parsectl();                  /* parse the control file */
  136.  
  137.    /* Normalize the first two paths for reading and writing */
  138.    fnsplit(path[0]->FilePath, drive, dir, filename, ext);
  139.    fnmerge(path[0]->FilePath, drive, dir, filename, ext);
  140.    fnsplit(path[1]->FilePath, drive, dir, filename, ext);
  141.    fnmerge(path[1]->FilePath, drive, dir, filename, ext);
  142.    fnsplit(path[2]->FilePath, drive, dir, filename, ext);
  143.    fnmerge(path[2]->FilePath, drive, dir, filename, ext);
  144.  
  145.    if((outfile = fopen(path[1]->FilePath, "wt")) == NULL) /* open output file */
  146.    {
  147.       printf("Error opening %s",path[1]->FilePath);
  148.       exit(255);
  149.    }
  150.  
  151.    if((fp = fopen(path[2]->FilePath, "rt")) == NULL) /* open header file */
  152.    {
  153.       printf("Error opening %s",path[2]->FilePath);
  154.       exit(255);
  155.    }
  156.  
  157.    if((newfile = fopen(path[0]->FilePath, "wt")) == NULL) /* open newfiles file */
  158.    {
  159.       printf("Error opening %s",path[0]->FilePath);
  160.       exit(255);
  161.    }
  162.  
  163.    aread("Welcome to FileList!");
  164.  
  165.    tmfile = localtime(&tnow);
  166.  
  167.    fprintf(outfile,"Report Started: %s\n",asctime(tmfile));
  168.    while(fgets(descrip,164,fp) != NULL)  /* write header file line by line */
  169.        fputs(descrip,outfile);
  170.  
  171.    fclose(fp);            /* Close header file */
  172.    fprintf(newfile,"Report Created: %s\n",asctime(tmfile));
  173.    fprintf(newfile,"Latest files to arrive at %sduring the last %d days:\n",systemname,days);
  174.    listfiles();           /* process each FILES.BBS */
  175.  
  176.    for(t=0;t<200;t++)  free(path[t]);   /* free the memory */
  177.    fclose(outfile);                    /* close the output file */
  178.    fclose(newfile);                    /* close the output file */
  179.    bios_move(23,1);                    /* put cursor at bottom of screen */
  180.    return(1);                          /* all done */
  181. }
  182.  
  183. /*------------------------------------------------------------------------------*/
  184.  
  185. /*
  186. **  commafmt()
  187. **
  188. **  Public domain by Bob Stout
  189. **
  190. **  Notes:  1. Use static buffer to eliminate error checks on buffer overflow
  191. **             and reduce code size.
  192. **          2. By making the numeric argument a long and prototyping it before
  193. **             use, passed numeric arguments will be implicitly cast to longs
  194. **             thereby avoiding int overflow.
  195. **          3. Use the thousands grouping and thousands separator from the
  196. **             ANSI locale to make this more robust.
  197. */
  198.  
  199.  
  200.  
  201. /* Buffer for formatted string  */
  202. /* Size of buffer               */
  203. /* Number to convert            */
  204.  
  205. commafmt(char *buf, int bufsize, long N)
  206. /*size_t commafmt(char *buf, int bufsize, long N)*/
  207. {
  208.    int len = 1, posn = 1, sign = 1;
  209.    char *ptr = buf + bufsize - 1;
  210.  
  211.    if (2 > bufsize)
  212.    {
  213. ABORT:          *buf = NUL;
  214.                 return 0;
  215.    }
  216.  
  217.    *ptr-- = NUL;
  218.    --bufsize;
  219.    if (0L > N)
  220.    {
  221.       sign = -1;
  222.       N = -N;
  223.    }
  224.  
  225.    for ( ; len <= bufsize; ++len, ++posn)
  226.    {
  227.       *ptr-- = (char)((N % 10L) + '0');
  228.       if (0L == (N /= 10L))
  229.       break;
  230.  
  231.       if (0 == (posn % 3))
  232.       {
  233.          *ptr-- = ',';
  234.          ++len;
  235.       }
  236.  
  237.       if (len >= bufsize)  goto ABORT;
  238.    }
  239.  
  240.    if (0 > sign)
  241.    {
  242.       if (0 == bufsize)    goto ABORT;
  243.       *ptr-- = '-';
  244.    }
  245.  
  246.    strcpy(buf, ++ptr);
  247.    return (size_t)len;
  248. }
  249.  
  250. /*------------------------------------------------------------------------------*/
  251.  
  252. int listfiles()
  253. {
  254.    FILE *fp;
  255.    static int i, j, count, test = 0, test2 = 0;
  256.    char desc[200];
  257.    char buf[20];
  258.    char mytemp[80];
  259.  
  260.    sprintf(mytemp,"Output File: %s",path[1]->FilePath);
  261.    areap(mytemp);
  262.    sprintf(mytemp,"New Files Output File: %s for %d days",path[0]->FilePath,days);
  263.    areap(mytemp);
  264.    for(i=3;i<start;i++)
  265.    {
  266.       test = strlen(path[i]->FilePath);
  267.       sprintf(mytemp,"%s",path[i]->FilePath);
  268.       mytemp[test - 1] = '\0';
  269.       aread(mytemp);
  270.       strcpy(keeppath,path[i]->FilePath);
  271.       strcat(path[i]->FilePath,"files.bbs");
  272.  
  273.       if((fp = fopen(path[i]->FilePath,"rt")) == NULL)
  274.       {
  275.          continue;
  276.       }
  277.       strcpy(mytemp,path[i]->AreaDesc);
  278.       mytemp[(strlen(path[i]->AreaDesc) - 1)] = '\0';
  279.       fprintf(outfile,"\n▓▒░%s ░▒▓\n",mytemp);
  280.       fprintf(newfile,"\n\n▓▒░%s ░▒▓\n",mytemp);
  281.  
  282.       test2 = strlen(path[i]->AreaDesc);
  283.  
  284.       sprintf(mytemp,"%d ",i-2);
  285.       test2 += strlen(mytemp);
  286.       strcat(mytemp,path[i]->AreaDesc);
  287.       mytemp[test2-1] = '\0';
  288.       areap(mytemp);
  289.  
  290.       count = areabytes = 0;
  291.  
  292.       while(fgets(desc,200,fp) != NULL)
  293.          if(processline(desc)) count++;
  294.  
  295.       numfiles[i] = count;
  296.       tempcount += count;
  297.  
  298.       if(count)
  299.       {
  300.          commafmt(buf,20,areabytes);
  301.          fprintf(outfile,"\n\n=-= Area Stats: %s Bytes in %d Files\n",buf,count);
  302.          files(tempcount);
  303.          commafmt(buf,20,numbytes);
  304.          print_atcolor(22,5,B_BLUE+F_YELLOW,buf);
  305.       }
  306.       else
  307.       {
  308.          fprintf(outfile,"\n\n=-= Area Stats: NO FILES\n");
  309.       }
  310.       for(j = 0; j < 72; j++)
  311.          fprintf(outfile,"*");
  312.  
  313.       fclose(fp);
  314.    }
  315.  
  316.    count = 0;
  317.  
  318.    message("Computing Statistics...");
  319.  
  320.    fprintf(outfile,"\n\n=-=-=-=-=-=-=\nFinal Report:\n=-=-=-=-=-=-=\n");
  321.    sprintf(mytemp,"=-=-=-=-=-=-= Final Report =-=-=-=-=-=-=");
  322.    areap(mytemp);
  323.  
  324.    for(i=3;i<start;i++)
  325.    {
  326.       fprintf(outfile,"       %3d Files in%s",numfiles[i],path[i]->AreaDesc);
  327.       count += numfiles[i];
  328.    }
  329.  
  330.    commafmt(buf,20,numbytes);
  331.  
  332.    sprintf(mytemp,"%4d Total Files in %s bytes",count, buf);
  333.    fprintf(outfile,"      ----\n      %s",mytemp);
  334.    areap(mytemp);
  335.    time(&tnow);
  336.    tmfile = localtime(&tnow);
  337.    fprintf(outfile,"\n\nReport Finished : %s",asctime(tmfile));
  338.    sprintf(mytemp,"* Produced automatically by FILELIST  (1991)  Erik Vanriper.  (1:107/230) *\n");
  339.    fprintf(outfile,mytemp);
  340.    fprintf(newfile,"\n%s",mytemp);
  341.    fprintf(newfile,"\nPress Enter To Continue: ");
  342.    message("Thank you for using FILELIST!");
  343.    return(1);
  344. }
  345.  
  346. /*------------------------------------------------------------------------------*/
  347.  
  348. void killspace(char *buffer)
  349. {
  350.    int test;
  351.  
  352.    test = strspn(buffer,whitespace);
  353.    strcpy(descrip,(buffer + test));
  354. }
  355.  
  356. /*------------------------------------------------------------------------------*/
  357.  
  358. int processline(char *desc)
  359. {
  360.    char filename[13], *test, check[80];
  361.    int result, c, i, d;
  362.  
  363.    if((desc[0] < '\x30') || (desc[0] > '\x7A') || ((desc[0] > '\x3A') && (desc[0] < '\x41')) || ((desc[0] > '\x5A') && (desc[0] < '\x61')))
  364.    {
  365.       fputs(desc,outfile);
  366.       return(0);
  367.    }
  368.  
  369.    test = strtok(desc," ");
  370.    strcpy(filename,test);
  371.    test = strtok(NULL,"\r\n");
  372.    strcpy(descrip,test);
  373.  
  374.    strcpy(check,keeppath);
  375.    strcat(check,"\\");
  376.    strcat(check,filename);
  377.  
  378.    killspace(descrip);
  379.  
  380.    if(stat(check, &info) !=0)   return(0);
  381.  
  382.    numbytes += info.st_size;
  383.    areabytes += info.st_size;
  384.  
  385.    tmfile = localtime(&info.st_atime);
  386.  
  387.    fprintf(outfile,"\n%-13s%6ld  %.2d-%.2d-%d",filename,info.st_size,
  388.                     (tmfile->tm_mon +1),tmfile->tm_mday,tmfile->tm_year);
  389.  
  390.    if((tnow - info.st_atime) < (long)((long)days * 86400L))
  391.    {
  392.       fprintf(newfile,"\n%-13s%6ld  %.2d-%.2d-%d  ",filename,info.st_size,
  393.                        (tmfile->tm_mon +1),tmfile->tm_mday,tmfile->tm_year);
  394.       new = 1;
  395.    }
  396.  
  397.    fprintf(outfile,((tnow - info.st_atime) < 2678400L) ? "* " : "  ");
  398.  
  399.    writedescrip();
  400.  
  401.    return(1);
  402. }
  403.  
  404. /*------------------------------------------------------------------------------*/
  405.  
  406. writedescrip()
  407. {
  408.    char *token;
  409.    int test, x = 0;
  410.  
  411.    test = strlen(descrip);
  412.    if(!test)
  413.    {
  414.       /*fprintf(outfile,"\n");*/
  415.       if(new) fprintf(newfile,"\n");
  416.       new = 0;
  417.       return(0);
  418.    }
  419.    if(test <= 47)
  420.    {
  421.       fprintf(outfile,"%s",descrip);
  422.       if(new) fprintf(newfile,"%s",descrip);
  423.       new = 0;
  424.       return(1);
  425.    }
  426.    else
  427.    {
  428.       token = strtok(descrip,whitespace);
  429.  
  430.       while(token != NULL)
  431.       {
  432.          x = x + strlen(token);
  433.  
  434.          if(x <= 47)
  435.          {
  436.             fprintf(outfile,"%s ",token);
  437.             if(new) fprintf(newfile,"%s ",token);
  438.             x = x + 1;
  439.          }
  440.  
  441.          else
  442.          {
  443.             x = 1;
  444.             fprintf(outfile,"\n                               %s ",token);
  445.             if(new) fprintf(newfile,"\n                               %s ",token);
  446.          }
  447.  
  448.          token = strtok(NULL,whitespace);
  449.       }
  450.    }
  451.    /*fprintf(outfile,"\n");*/
  452.    /*if(new) fprintf(newfile,"\n");*/
  453.    new = 0;
  454.    return(1);
  455. }
  456.  
  457. /*------------------------------------------------------------------------------*/
  458.  
  459. int parsectl()
  460. {
  461.    FILE *fp;
  462.    int result, c, i, d;
  463.    char wholeline[200], *test;
  464.  
  465.    if ((fp = fopen(input,"rt")) == NULL)
  466.    {
  467.       cls();
  468.       printf("Can't find file %s",input);
  469.       exit(255);
  470.    }
  471.  
  472.    message("Parsing configuration file...");
  473.  
  474.    fgets(wholeline,200,fp);  /* Get system name */
  475.    strcpy(systemname,wholeline);
  476.    fgets(wholeline,200,fp);  /* Get NEWFILES days */
  477.    days = atoi(wholeline);
  478.    
  479.    c = 0;
  480.    while(fgets(wholeline,200,fp) != NULL)
  481.    {
  482.       test = strstr(wholeline, "\x20");
  483.  
  484.       if(test == NULL)
  485.       {
  486.          strcpy(path[c]->FilePath,wholeline);
  487.          d = strlen(path[c]->FilePath);
  488.          path[c]->FilePath[d] = '\0';
  489.       }
  490.       else
  491.       {
  492.          strcpy(path[c]->AreaDesc,test);
  493.          result = strlen(wholeline);
  494.          i = strlen(path[c]->AreaDesc);
  495.          strncpy(path[c]->FilePath,wholeline,(result - i));
  496.          path[c]->FilePath[(result - i)] = '\0';
  497.       }
  498.       c++; start++;
  499.    }
  500.    fclose(fp);
  501.    message("Working...");
  502.    return(1);
  503. }
  504.  
  505. /*------------------------------------------------------------------------------*/
  506.  
  507. void print_atcolor(int x, int y, int attr, unsigned char *line)
  508. {
  509.    /*const long vmode = 0x00000449;*/
  510.    int  i = 0;
  511.    int far *video_base;
  512.    if((cga) || (ega) || (vga) || (mcga))
  513.       video_base = (int far *)0xb8000000;
  514.    else video_base = (int far *)0xb0000000;
  515.    while (*(line + i))
  516.       *(video_base + (x * 80) + y++) = *(line + i++) | (attr<<8);
  517. }
  518.  
  519. /*------------------------------------------------------------------------------*/
  520.  
  521. void files(int t)
  522. {
  523.    char str[10];
  524.    sprintf(str,"%d",t);
  525.    print_atcolor(22,71,B_BLUE+F_YELLOW,str);
  526. }
  527.  
  528. /*------------------------------------------------------------------------------*/
  529.  
  530. void areap(char *str)
  531. {
  532.    bios_scroll_up(1, 9, 2, 19, 77);
  533.    print_atcolor(19,3,B_BLACK+F_LRED,str);
  534. }
  535.  
  536. /*------------------------------------------------------------------------------*/
  537.  
  538. void aread(char *str)
  539. {
  540.    bios_scroll_up(1, 2, 2, 6, 77);
  541.    print_atcolor(6,3,B_BLACK+F_LCYAN,str);
  542. }
  543.  
  544. /*------------------------------------------------------------------------------*/
  545.  
  546. void message(char *str)
  547. {
  548.    print_atcolor(22,18,B_BLUE+F_WHITE,"║                                               ");
  549.    print_atcolor(22,22,B_BLUE+F_YELLOW,str);
  550. }
  551.  
  552. /*------------------------------------------------------------------------------*/
  553.  
  554. void mainscreen()
  555. {
  556.    int x;
  557.  
  558.    print_atcolor( 0,0,B_BLUE+F_WHITE,"╔═════════════════════════ FILELIST  by Erik H. VanRiper ══════════════════════╗");
  559.    for(x = 1; x < 23; x++)
  560.    print_atcolor(x ,0,B_BLUE+F_WHITE,"║                                                                              ║");
  561.    print_atcolor(23,0,B_BLUE+F_WHITE,"╚══════════════════════════════════════════════════════════════════════════════╝");
  562.    print_atcolor(21,66,B_BLUE+F_WHITE,"╦═ #  Files ═╣");
  563.    print_atcolor(22,66,B_BLUE+F_WHITE,"║            ║");
  564.    print_atcolor(23,66,B_BLUE+F_WHITE,"╚════════════╝");
  565.    print_atcolor(21,0,B_BLUE+F_WHITE,"╠══ Total Bytes ══╦");
  566.    print_atcolor(22,0,B_BLUE+F_WHITE,"║                 ║");
  567.    print_atcolor(23,0,B_BLUE+F_WHITE,"╚═════════════════╝");
  568.    print_atcolor(21,18,B_BLUE+F_WHITE,"╦═══════════════════ Messages ══════════════════╦");
  569.    print_atcolor(23,18,B_BLUE+F_WHITE,"╩═══════════════════════════════════════════════╩");
  570.    print_atcolor( 8,1,B_BLACK+F_WHITE,"╔═══════════════════════════════ Area Processing ════════════════════════════╗");
  571.    for(x = 9; x < 20; x++)
  572.    print_atcolor(x ,1,B_BLACK+F_WHITE,"║                                                                            ║");
  573.    print_atcolor(20,1,B_BLACK+F_WHITE,"╚════════════════════════════════════════════════════════════════════════════╝");
  574.    print_atcolor( 1,1,B_BLACK+F_WHITE,"╔═══════════════════════════════ Area Directory ═════════════════════════════╗");
  575.    for(x = 2; x < 7; x++)
  576.    print_atcolor(x ,1,B_BLACK+F_WHITE,"║                                                                            ║");
  577.    print_atcolor(7 ,1,B_BLACK+F_WHITE,"╚════════════════════════════════════════════════════════════════════════════╝");
  578. }
  579.  
  580. /*==============================================================================*/
  581.  
  582. /* The following bios_*() funtions were taken from the August 1991 edition of
  583. ** the C Users Journal<tm> and have the following copyright notice:
  584. **
  585. ** IBM bios scrren control package
  586. ** Copyright Dave Newman 1991
  587. ** Permission  to use these routines for any reason is granted as long as this
  588. ** copyright notice is included.
  589. */
  590.  
  591. /*------------------------------------------------------------------------------*/
  592.  
  593. void bios_open()
  594. {
  595.     union REGS regs;
  596.  
  597.     /* determine the display mode */
  598.     regs.x.ax = 0x0f00;
  599.     int86(0x10,®s,®s);
  600.     cur_mode = regs.h.al;
  601.     cur_page = regs.h.bh;
  602.     /*num_cols = regs.h.ah;*/
  603.  
  604.     none = mono = herc = cga = ega = vga = mcga = color_disp = b_w = 0;
  605.     vtest();
  606. }
  607.  
  608. /*------------------------------------------------------------------------------*/
  609.  
  610. /* video adapter type */
  611. void vtest()
  612. {
  613.     union REGS regs;
  614.     unsigned char hold_a_byte;
  615.     int i;
  616.  
  617.     regs.h.ah = 0x1a;
  618.     regs.h.al = 0;
  619.     int86(0x10,®s,®s);
  620.  
  621.     if(regs.h.al == 0x1a)
  622.     {
  623.         if(regs.h.bl < 0x0a) vga = 1;
  624.         else mcga = 1;
  625.         color_disp = 1;
  626.         return;
  627.     }
  628.  
  629.     regs.h.ah = 0x12;
  630.     regs.h.bl = 0x10;
  631.     int86(0x10,®s,®s);
  632.     if(regs.h.bl != 0x10)
  633.     {
  634.         ega = 1;
  635.         if(regs.h.bh == 0)  color_disp = 1;
  636.         else b_w = 1;
  637.         return;
  638.     }
  639.  
  640.     bios_mode();
  641.  
  642.     if(cur_mode != 7)
  643.     {
  644.         outp(0x3d4,0x0f);
  645.         hold_a_byte = inp(0x3d5);
  646.         outp(0x3d5,0x63);
  647.         for(i = 0; i < 100; i++);
  648.         if(inp(0x3d5) == 0x63)
  649.         {
  650.             outp(0x3d5,hold_a_byte);
  651.             cga = 1;
  652.             color_disp = 1;
  653.             return;
  654.         }
  655.         else
  656.         {
  657.             outp(0x3d5,hold_a_byte);
  658.             none = 1;
  659.             color_disp = 1;
  660.             return;
  661.         }
  662.     }
  663.  
  664.     outp(0x3b4,0x0f);
  665.     hold_a_byte = inp(0x3b5);
  666.     outp(0x3b5,0x63);
  667.     for(i = 0; i < 100; i++);
  668.     if(inp(0x3b5) == 0x63)
  669.     {
  670.         outp(0x3b5,hold_a_byte);
  671.         none = 1;
  672.         b_w = 1;
  673.         return;
  674.     }
  675.     outp(0x3b5,hold_a_byte);
  676.     hold_a_byte = inp(0x3ba);
  677.     hold_a_byte &= 0x80;
  678.     for(i = 0; i < 1000; i++)
  679.     {
  680.         if(inp(0x3ba) & 0x80 != hold_a_byte)
  681.         {
  682.             herc = 1;
  683.             break;
  684.         }
  685.     }
  686.     if(!herc)
  687.     {
  688.         mono = 1;
  689.         b_w = 1;
  690.         return;
  691.     }
  692.     hold_a_byte = inp(0x3ba);
  693.     switch(hold_a_byte)
  694.     {
  695.         case 0x50: color_disp = 1; break;
  696.         case 0x00: b_w = 1;   break;
  697.     }
  698. }
  699.  
  700. /*------------------------------------------------------------------------------*/
  701.  
  702. int bios_mode()
  703. {
  704.     union REGS regs;
  705.     regs.h.ah = 15;
  706.     int86(0x10,®s,®s);
  707.     cur_mode = regs.h.al;
  708.     return(regs.h.al);
  709. }
  710.  
  711.  
  712. /*------------------------------------------------------------------------------*/
  713.  
  714. void bios_scroll_up(int count, int sr, int sc, int er, int ec)
  715. {
  716.     union REGS regs;
  717.     regs.h.al = count;
  718.     regs.h.ch = sr;
  719.     regs.h.cl = sc;
  720.     regs.h.dh = er;
  721.     regs.h.dl = ec;
  722.     regs.h.bh = cur_attr;
  723.     regs.h.ah = 6;
  724.     int86(0x10,®s,®s);
  725. }
  726.  
  727. /*------------------------------------------------------------------------------*/
  728.  
  729. /* scroll active page dn.  good to clear entire screen */
  730. void bios_scroll_dn(int count, int sr, int sc, int er, int ec)
  731. {
  732.     union REGS regs;
  733.     regs.h.al = count;
  734.     regs.h.ch = sr;
  735.     regs.h.cl = sc;
  736.     regs.h.dh = er;
  737.     regs.h.dl = ec;
  738.     regs.h.bh = cur_attr;
  739.     regs.h.ah = 7;
  740.     int86(0x10,®s,®s);
  741. }
  742.  
  743.  
  744. /*------------------------------------------------------------------------------*/
  745.  
  746. void bios_move(int row, int col)
  747. {
  748.     union REGS regs;
  749.  
  750.     regs.h.dh = row;
  751.     regs.h.dl = col;
  752.     regs.h.ah = 2;
  753.     regs.h.bh = cur_page;
  754.     int86(0x10,®s,®s);
  755.     /*cur_row = row;
  756.     cur_col = col;*/
  757. }
  758.